#include "gtest/gtest.h"
// #include <mockcpp/mokc.h>
// #include <mockcpp/mockcpp.hpp>

#include <vector>
#include <iostream>

#include "topoinfo_struct.h"
#include "log.h"
#include "checker_def.h"
#include "topo_meta.h"
#include "testcase_utils.h"
#include "alg_template_register.h"
#include "broadcast_nhr_v1_pub.h"
#include "checker.h"

using namespace checker;
using namespace hccl;

class TemplateRegisterTest : public testing::Test {
protected:
    static void SetUpTestCase()
    {
        std::cout << "TemplateRegisterTest set up." << std::endl;
    }

    static void TearDownTestCase()
    {
        std::cout << "TemplateRegisterTest tear down." << std::endl;
    }

    virtual void SetUp()
    {
        const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info();
        std::string caseName = "analysis_result_" + std::string(test_info->test_case_name()) + "_" + std::string(test_info->name());
        Checker::SetDumpFileName(caseName);
    }

    virtual void TearDown()
    {
        Checker::SetDumpFileName("analysis_result");
        // GlobalMockObject::verify();
        // 这边每个case执行完成需要清理所有的环境变量，如果有新增的环境变量，需要在这个函数中进行清理
        ClearHcclEnv();
    }
};

TEST_F(TemplateRegisterTest, template_regist_rereg)
{
    HcclResult ret;
    ret = hccl::AlgTemplateRegistry::Instance().Register(TemplateType::TEMPLATE_BROADCAST_NHR_V1,
        DefaultTemplateCreator<BroadcastNHRV1>);

    EXPECT_NE(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(TemplateRegisterTest, template_regist_outofrange)
{
    HcclResult ret;
    ret = hccl::AlgTemplateRegistry::Instance().Register(static_cast<TemplateType>(100),
        DefaultTemplateCreator<BroadcastNHRV1>);

    EXPECT_NE(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(TemplateRegisterTest, template_get_outofrange)
{
    HcclDispatcher dispatcher_;
    auto ret = hccl::AlgTemplateRegistry::Instance().GetAlgTemplate(static_cast<TemplateType>(100),
        dispatcher_);

    EXPECT_EQ(ret, nullptr);
}